package com.iptv2.system.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iptv2.system.aop.Logging;
import com.iptv2.system.dao.OrganDao;
import com.iptv2.system.dao.OrganDataDao;
import com.iptv2.system.pojo.Organ;
import com.iptv2.system.pojo.OrganData;
import com.iptv2.system.service.OrganService;

@Logging
@Service
public class OrganServiceImpl extends BaseServiceImpl<Organ> implements OrganService {

	@Autowired private OrganDao organDao;
	@Autowired private OrganDataDao organDataDao;

	@Override
	public List<Organ> getChildren(String parentId,Integer status) {
		return organDao.getChildren(parentId,status);
	}

	@Override
	public void sort(Organ[] organs) {
		organDao.sort(organs);
	}
	
	@Override
	public void move(String targetId, String sourceId, String point) {
		organDao.move(targetId, sourceId, point);
	}

	@Override
	public void functionSetup(String organId, String[] checkedFuncId,String[] uncheckedFuncId){
		organDao.functionSetup(organId, checkedFuncId, uncheckedFuncId);
	}

	@Override
	public Organ getMainEmployee(String userId) {
		return organDao.getMainEmployee(userId);
	}

	@Override
	public Organ getDepartment(String empOrganId) {
		return organDao.getDepartment(empOrganId);
	}
	
	@Override
	public Organ getMainDepartment(String userId) {
		return organDao.getMainDepartment(userId);
	}

	@Override
	public List<Organ> getParents(String organId) {
		return organDao.getParents(organId);
	}
	
	/**
	 * 根据userId获取用户的所有职位信息
	 * @param userId
	 * @return
	 */
	public List<Organ> getOrgansByUserId(String userId) {
		return organDao.getOrgansByUserId(userId);
	}

	/**
	 * 设置用户的主要员工
	 * @param userId
	 */
	public void setMainEmployee(String userId,String organId) {
		organDao.setMainEmployee(userId, organId);
	}
	
	/**
	 * 根据roleId获取用户的所有职位信息
	 * 获取拥有该角色的所有用户,并在组织机构表中找到该用户设置为主要的职位
	 * @param roleId
	 * @return
	 */
	public List<Organ> getOrgansByRoleId(String roleId) {
		return organDao.getOrgansByRoleId(roleId);
	}

	@Override
	public List<OrganData> getOrganDataByOrganId(String organId) {
		return organDataDao.getDataByOrganId(organId);
	}

	@Override
	public void addOrganDatas(String organId, OrganData[] datas) {
		organDataDao.add(organId, datas);
	}

}
